package com.example.a33mvvm.liu;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.example.base_mvvm.base.BaseViewModel;
import com.example.base_mvvm.entity.PushEntity;
import com.example.base_mvvm.entity.StopPushEntity;
import com.example.base_mvvm.net.Const;
import com.google.gson.Gson;

import java.util.HashMap;

import okhttp3.MediaType;
import okhttp3.RequestBody;

public class PushViewModel extends BaseViewModel<PushRepo> {
    public MutableLiveData<PushEntity> success_start = new MutableLiveData<>();
    public MutableLiveData<String> failure_start = new MutableLiveData<>();
    public MutableLiveData<StopPushEntity> success_stop = new MutableLiveData<>();
    public MutableLiveData<String> failure_stop = new MutableLiveData<>();
    public PushViewModel(@NonNull Application application) {
        super(application);
    }
    public void startLive(String address,String caption){
        HashMap<String, String> map = new HashMap<>();
        map.put(Const.PUSH_ADDRESS,address);
        map.put(Const.PUSH_CAPTION,caption);
        String json = new Gson().toJson(map);
        RequestBody body = RequestBody.create(MediaType.parse(Const.PARSE),json);
        repo.startLive(body,success_start,failure_start);
    }
    public void stopLive(){
        repo.stopLive(success_stop,failure_stop);
    }

    @Override
    protected PushRepo createRepo() {
        return new PushRepo();
    }
}
